<!--编辑教学活动评价-->
<template>
  <div class="wrapper-container" style="width:100%">
    <el-form ref="form" class="my-form" style="margin-top:0">
      <el-row class="single-row">
        <el-col :span="24">
          <el-row class="item-row">
            <el-col class="name-col" :span="6"> 学期</el-col>
            <el-col class="content-col" :span="18">
              <el-select
                v-model="tableData.term"
                style="width: 180px"
                size="mini"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in xueqiList"
                  :key="item.value"
                  :label="item.xqmc"
                  :value="item.xqmc"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
      <el-row class="single-row">
        <el-col :span="24">
          <el-row class="item-row">
            <el-col class="name-col" :span="6"> 评价活动名称</el-col>
            <el-col class="content-col" :span="18">
              <el-input
                v-model="tableData.evalprojectname"
                style="width: 50%"
                size="small"
              ></el-input>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
      <el-row class="single-row">
        <el-col :span="12">
          <el-row class="item-row">
            <el-col class="name-col" :span="12"> 开始时间</el-col>
            <el-col class="content-col" :span="12">
              <el-date-picker
                v-model="tableData.begindate"
                type="datetime"
                placeholder="选择开始时间"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 55%"
              >
              </el-date-picker>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="12">
          <el-row class="item-row">
            <el-col class="name-col" :span="12"> 结束时间</el-col>
            <el-col class="content-col" :span="12">
              <el-date-picker
                v-model="tableData.enddate"
                type="datetime"
                placeholder="选择结束时间"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 55%"
              >
              </el-date-picker>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
      <el-row class="single-row">
        <el-col :span="24">
          <el-row class="item-row">
            <el-col class="name-col" :span="6"> 指标体系</el-col>
            <el-col class="content-col" :span="18">
              <SelectItem style="width: 200px"
                          :name="''"
                          :value="guidename"
                          @change="
                  (e) => {
                    guidename = e;
                  }
                "
                          :xqList="systemList"
              ></SelectItem>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
      <el-row class="single-row">
        <el-col :span="24">
          <el-row class="item-row">
            <el-col class="name-col" :span="6"> 各个等级比例限制</el-col>
            <el-col class="content-col" :span="18">
              <div>
                <span>A:&ensp;</span>
                <el-input v-model="proporA" size="mini" oninput ="value=value.replace(/[^\d]/g,'')" placeholder="" style="width:120px"></el-input>&ensp;%
              </div>
              <div style="margin-left:70px">
                <span>B:&ensp;</span>
                <el-input v-model="proporB" size="mini" oninput ="value=value.replace(/[^\d]/g,'')" placeholder="" style="width:120px"></el-input>&ensp;%
              </div>
              <div style="margin-left:70px">
                <span>CD:&ensp;</span>
                <el-input v-model="proporC" size="mini" oninput ="value=value.replace(/[^\d]/g,'')" placeholder="" style="width:120px"></el-input>&ensp;%
              </div>
              
              <!--              <el-input type="text" style="width: 110px" v-for="(item,index) in this.proportionalList " :key='index'-->
              <!--                        v-model="baseInfo['level'+item]"-->
              <!--                        size="mini">-->
              <!--              </el-input>-->
              <!-- <InputItem v-for="(item,index) in this.proportionalList " :key='index'
                         :name="propor['level'+index]"
                         :value="propor['level'+index]"
                         @input="
                              (e) => {
                                propor['level'+index] = e;
                              }
                            "
                         :endText="'%'"
              ></InputItem> -->
            </el-col>
          </el-row>
        </el-col>
      </el-row>
      <el-row class="single-row">
        <el-col :span="24">
          <el-row class="item-row" style="height: 415px">
            <el-col class="name-col" style="height: 100%" :span="6">
              评价说明
            </el-col>
            <el-col class="content-col" style="height: 100%" :span="18">
              <el-input
                style="width: 96%; margin: 10px 0; height: 400px"
                type="textarea"
                placeholder="请输入内容"
                v-model="tableData.teaching"
              >
              </el-input>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
    </el-form>


    <!-- <div class="bottom-block">
      <div style="width: 300px; display: flex; justify-content: space-around">
        <ButtonItem
          :name="'保存'"
          :link="''"
          :icon="''"
          :buttonColor="'yellow'"
          @click="save"
        ></ButtonItem>

        <ButtonItem
          :name="'取消'"
          :link="''"
          :icon="''"
          :buttonColor="'red'"
          @click="Cancel"
        ></ButtonItem>
      </div>
    </div> -->
    <div class="button-group">
      <div @click="save">
        <div>保 存</div>
      </div>
      <div @click="Cancel">
        <div>取 消</div>
      </div>
    </div>
  </div>
</template>

<script>
import SelectItem from "../../../components/SelectItem.vue";
import InputItem from "../../../components/InputItem.vue";
import ButtonItem from "../../../components/ButtonItem.vue";
import Subscript from "../../../components/Subscript.vue";

import { reqGetXqList } from "@/api/course/courses";
import {ByAllRankAndGuide, insert2} from "@/api/evaluation/setActivityEvaluations";
import {pjevalprojectById} from "../../../api/teacher/admin";

export default {
  components: {
    SelectItem,
    InputItem,
    ButtonItem,
    Subscript,
  },
  data() {
    return {

      tableData: {
        // guiderankoption: '',//各个等级比例
        teaching: '',//评教说明
        guidename: '',//指标项名称
        evalprojectname: '',//评价活动名称
        enddate: '',//结束时间
        begindate: '',//开始时间
        term: '',//学期
        type:1,
        zhibiaoid:'',
      },

      term: "2021春",
      xueqiList: [],
      guidename: '',
      systemList: [],
      teacherList: [],
      classList: [],
      baseInfo: {
        courseName: "",
      },
      proporA:'',
      proporB:'',
      proporC:'',
      proportionalList: [],
      multipleSelection: [],
      // propor: {
      //   level1: "",
      //   level2: "",
      //   level3: "",
      //   level4: "",
      //   level5: "",
      //   level6: "",
      //   level7: "",
      //   level8: "",
      //   level9: "",
      //   level10: "",
      //   level0: ""
      // }
    };
  },
  watch: {
    // guidename(val) {
    //   if (val) {
    //     this.proportionalList = this.systemList[val].guiderankoption.split(',')
    //   }

    // },
  },
  mounted() {
    this.getXqList();
    this.ByAllRankAndGuide()
    // this.pjevalprojectById()
  },

  methods: {
 // 获取学期院历列表
    async getXqList() {
      const result = await reqGetXqList();
      if (result.data.code == 200) {
        this.xueqiList = result.data.data;
      }
    },
    
    ByAllRankAndGuide() {
      ByAllRankAndGuide().then(res => {
        if (res.data.code === 200) {
          let data = res.data.data
          let arr = []
          for (const dataKey in data) {
            let obj = {...data[dataKey].pjEvalguide, ...data[dataKey].pjGuiderank}
            obj = {
              value: dataKey,//obj.guiderankoption
              label: obj.guidename,
              guideid:obj.guideid,

              //zhibiaoid  指标ID

              guiderankoption: obj.guiderankoption,
            }

            arr.push(obj)

          }
          this.systemList = arr
          this.pjevalprojectById(arr)
      
        }
        // console.log(this.systemList)
      })
    },
    //查询
    pjevalprojectById(arr){
      let id = {}
      id = this.$route.query.evalprojectid
      pjevalprojectById(id).then(res => {
        this.tableData = res.data.data
        this.guidename = this.tableData.pjEvalguide.guidename;
        if (this.guidename) {
          let _arr = this.tableData.proportionallimit.split(',');
          _arr.forEach(ele => {
            this.proportionalList.push(ele.split(":")[1]);
          });
          this.proporA = this.proportionalList[0]*100;
          this.proporB = this.proportionalList[1]*100;
          this.proporC = this.proportionalList[2]*100;
        }
      })
    },

    save() {
      let obj = this.tableData
      let arr = []
      if (!obj.term) {
        this.$message.error('学期未填写');
        return
      }
      if (!obj.evalprojectname) {
        this.$message.error('评价活动名称未填写');
        return
      }
      if (!obj.begindate) {
        this.$message.error('开始时间未填写');
        return
      }
      if (!obj.enddate) {
        this.$message.error('结束时间未填写');
        return
      }
      let guideid= obj.pjEvalguide.guideid ? obj.pjEvalguide.guideid : '';
      if (guideid) {
        obj.zhibiaoid = guideid
      } else {
        this.$message.error('指标项名称未填写');
        return
      }
      // for (let i = 0; i < this.proportionalList.length; i++) {
      //   if (this.propor["level" + i]) {
      //     let obj = this.proportionalList[i] + ':' + this.propor["level" + i]
      //     arr.push(obj)
      if(this.proporA === '' || this.proporB === '' || this.proporC === ''){
        this.$message.error('各个等级比例限制中有未填写项');
        return
      }
      if (!obj.teaching) {
        this.$message.error('评教说明未填写');
        return
      }

      obj.type = 1
      let proporSum = Number(this.proporA) + Number(this.proporB) +  Number(this.proporC);
      if(proporSum > 100){
        this.$message.error("等级比例之和不能大于100");
      } else {
        obj.proportionallimit = 'A:' + this.proporA /100 + ',B:' + this.proporB /100 + ',C:' + this.proporC /100 + ',D:0';
        return new Promise(() => {
          insert2(obj).then(res => {
            console.log(res.status)
            if (res.status === 200) {
              let pathname = '/' + window.location.pathname.split('/')[1]
              this.$router.push(pathname + "/examination/setPrintEntryb");
            }
          })
        })
      }
    },
    Cancel(){
      let pathname = '/' + window.location.pathname.split('/')[1]
      this.$router.push(pathname + "/examination/setPrintEntryb");
    },



  },
  computed: {},
};
</script>
<style lang="less" scoped>
.button-group {
  cursor: pointer;
  margin-top: 50px;
  text-align: center;

  > div {
    display: inline-block;
    font-size: 18px;
    padding: 6px 22px;
    border-radius: 6px;

    &:nth-child(1) {
      color: #f3b815;
      border: 1px solid #f3b815;
      background: #fff6ef;
      margin-right: 139px;
    }

    &:nth-child(2) {
      color: #ff3819;
      border: 1px solid #ff3819;
      background: #ffefef;
    }
  }
}
/deep/.el-date-editor .el-input__icon{
  line-height: 42px;
}
.el-textarea__inner {
  border-color: #004ca7;
  font-size: 14px;
  color: #004ca7;
  font-family: "Microsoft YaHei";
  height: 90px;
}

.search-container {
  justify-content: flex-start !important;
}

.search-button {
  cursor: pointer;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: 27px;
  background: #f1f8fe;
  border: 1px solid #51aef6;
  border-radius: 6px;

  > span {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #51aef6;
  }

  > img {
    width: 19px;
    height: 19px;
    margin-right: 4px;
  }
}

.table-container {
  margin-top: 30px;

  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
}
</style>

<style lang="less" scoped>
.item-row .el-col {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  min-height: 70px;
  border-right: none !important;
}

.item-row .el-col:not(:first-child) {
  border-left: 1px solid rgba(0, 76, 167, 0.39);
}

.single-row .el-col:not(:last-child) {
  border-right: 1px solid rgba(0, 76, 167, 0.39);
}

.my-form .single-row:not(:last-child) {
  border-bottom: 1px solid rgba(0, 76, 167, 0.39);
}

.name-col {
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  color: #004ca7;
  background: rgba(77, 129, 192, 0.1);
}

.content-col {
  padding-left: 40px;
  color: #004ca7;
}

.wrapper-container {
  .my-form {
    width: 100%;
    border: 1px solid rgba(0, 76, 167, 0.8);
    margin: 57px auto 19px;
    border-radius: 9px;
  }
}

@import "../../../styles/special.less";
.bottom-block {
  padding-top: 30px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}

.table-container ::v-deep .el-table--border .el-table__cell:first-child .cell {
  padding-left: 10px !important;
}

.filter-button1::v-deep .el-radio-button .el-radio-button__inner {
  border-radius: 6px !important;
  border: 1px solid rgb(245, 134, 106);
  color: rgb(245, 134, 106);
  background-color: rgb(254, 237, 226);
}

.filter-button1::v-deep
.el-radio-button__orig-radio:checked
+ .el-radio-button__inner {
  border: 1px solid rgb(245, 134, 106);
  color: white;
  background-color: rgb(245, 134, 106);
}

.filter-button {
  display: flex;
  margin-top: 27px;
}

.wrapper-container {
  width: 1711px;
  margin: 0 auto;
}

.table-container {
  margin-top: 30px;

  .table-data {
    margin-top: 10px;
    border: 0.8px solid #004ca7;
    border-radius: 9px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.save-button {
  width: 87px;
  height: 36px;
  line-height: 36px;
  background: #fff6ef;
  border: 1px solid #f3b815;
  border-radius: 6px;
  font-size: 18px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #f3b815;
  text-align: center;
  margin: 82px auto;
}

.zuoyou {
  width: 200px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
</style>
<style lang="less" scoped>
/deep/ .search-container-item .el-select {
  width: 180px !important;
}

/deep/.el-date-editor .el-input__prefix {
 right:8px;
}

</style>
